/**
 * FileName: BusinessCode
 * Author: Wb
 * Date: 2025/9/24 14:12
 * Description:
 * History:
 */
package org.test.device.utils;

import lombok.Data;

import java.util.Map;

/**
 * 〈一句话功能简述〉<br>
 * 〈状态码〉
 *
 * @author Wb
 * @create 2025/9/24
 * @since 1.0.0
 */
public enum BusinessCode {

    //成功
    SUCCESS(200000),
    // 客户端相关错误
    CLIENT_ID_FORMAT_ERROR(400001),  // 客户端ID格式错误

    // 产品相关错误
    PRODUCT_NOT_FOUND_OR_DISABLED(400002),  // 产品不存在或未启用

    // 设备相关错误
    DEVICE_NOT_FOUND_OR_DISABLED(400003),   // 设备不存在或未启用

    DEVICE_NOT_BELONG_TO_PRODUCT(400004),   // 设备不属于该产品

    /**
     * 服务器错误
     */
    SERVER_ERROR(200002),

    // 认证相关错误
    AUTHENTICATION_FAILED(400005);  // 用户名或密码错误

    private long code;

    BusinessCode(final long code) {
        this.code = code;
    }

    public long getCode() {
        return code;
    }

    public static BusinessCode getBusinessCode(final Integer code) {
        if (code == null) {
            return null;
        }
        for (final BusinessCode businessCode : values()) {
            if (businessCode.code == code) {
                return businessCode;
            }
        }
        throw new IllegalArgumentException("Not matching type for code:" + code);
    }
}